package com.tanhua.server.controller;

import com.tanhua.model.vo.CountsVo;
import com.tanhua.model.vo.FriendsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息管理 控制层
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {


    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户信息管理-查询用户资料
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity getUserInfo(Long userID) {
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userID);
        return ResponseEntity.ok(userInfoVo);
    }


    /**
     * 用户信息管理-更新用户资料
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo userInfoVo) {
        userInfoService.updateUserInfo(userInfoVo);
        return ResponseEntity.ok(null);
    }


    /**
     * 分页查询相互喜欢列表
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity eachLove(@PathVariable Integer type, @RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize,String nickname) {
        PageResult<FriendsVo> vo = null;
        switch (type) {
            case 4:
                //谁看过我列表
                vo =  userInfoService.visitorsMe(page, pageSize, nickname);
                break;
            case 1:
                //调用服务查询相互喜欢列表
                vo = userInfoService.eachLove(page, pageSize, nickname);
                break;
            case 2:
                //我的喜欢列表
                vo =  userInfoService.findMyLove(page, pageSize, nickname);
                break;
            case 3:
                //粉丝
                vo = userInfoService.fansListPage(page, pageSize, nickname);
                break;

        }
        return ResponseEntity.ok(vo);
    }

    /**
     * 喜欢取消
     */
    @RequestMapping(value = "/like/{uid}", method = RequestMethod.DELETE)
    public ResponseEntity deleteLove(@PathVariable("uid") Long uid) {
        userInfoService.deleteLove(uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     */

    @RequestMapping(value = "/counts", method = RequestMethod.GET)

    public ResponseEntity counts() {

        CountsVo countsVo = userInfoService.counts();

        return ResponseEntity.ok(countsVo);
    }

    /**
     * 粉丝 喜欢
     */
    @PostMapping("/fans/{likeUserId}")
    public ResponseEntity loveFansList(@PathVariable("likeUserId") Long likeUserId) {
        userInfoService.loveFansList(likeUserId);
        return ResponseEntity.ok(null);
    }




}
